﻿#region RDIFramework.NET-generated
//------------------------------------------------------------------------------
//     RDIFramework.NET（.NET快速信息化系统开发、整合框架）是基于.NET的快速信息化系统开发、整合框架，给用户和开发者最佳的.Net框架部署方案。
//     RDIFramework.NET平台包含基础公共类库、强大的权限控制、模块分配、数据字典、自动升级、各商业级控件库、工作流平台、代码生成器、开发辅助
//工具等，应用系统的各个业务功能子系统，在系统体系结构设计的过程中被设计成各个原子功能模块，各个子功能模块按照业务功能组织成单独的程序集文
//件，各子系统开发完成后，由RDIFramework.NET平台进行统一的集成部署。
//
//	框架官网：http://www.rdiframework.net/
//	框架博客：http://blog.rdiframework.net/
//  版权所有：海南国思软件科技有限公司
//	交流QQ：406590790 
//	邮件交流：406590790@qq.com
//	其他博客：
//    http://www.cnblogs.com/huyong 
//    http://blog.csdn.net/chinahuyong
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由RDIFramework.NET平台代码生成工具自动生成。
//     运行时版本:4.0.30319.1
//
//     对此文件的更改可能会导致不正确的行为，并且如果
//     重新生成代码，这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
#endregion

using System;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.ServiceModel;

namespace .BizLogic
{
	using RDIFramework.BizLogic;
	using RDIFramework.Utilities;

	/// <summary>
	/// PmProjectsService
	/// pm_项目表服务层
	/// 
	/// 修改记录
	/// 
	///	2025-01-18 版本：3.5  建立pm_项目表服务层。
	///		
	/// 版本：3.5
	///
	/// <author>
	///	<name></name>
	///	<date>2025-01-18</date>
	/// </author> 
	/// </summary>
	[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
	public class PmProjectsService : System.MarshalByRefObject, IPmProjectsService
	{
		private string serviceName = "PmProjects";
		
		/// <summary>
		/// RDIFramework.NET框架数据库连接
		/// </summary>
		private readonly string RDIFrameworkDbConection = SystemInfo.RDIFrameworkDbConection;

		/// <summary>
		/// 业务数据库连接字符串
		/// </summary>
		private readonly string BusinessDbConnection = SystemInfo.BusinessDbConnection;

		#region public string Add(UserInfo userInfo, PmProjectsEntity entity, out string statusCode, out string statusMessage) 新增pm_项目表
		/// <summary>
		/// 新增pm_项目表
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="entity">pm_项目表实体</param>
		/// <param name="statusCode">返回状态码</param>
		/// <param name="statusMessage">返回状态消息</param>
		/// <returns>主鍵</returns>
		public string Add(UserInfo userInfo, PmProjectsEntity entity, out string statusCode, out string statusMessage)
		{
			var returnValue = string.Empty;
            string returnCode = string.Empty;
            string returnMessage = string.Empty;
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, "新增实体");

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                var manager = new PmProjectsManager(dbProvider, userInfo);
                returnValue = manager.Add(entity);
				if (!string.IsNullOrEmpty(returnValue))
                {
                    returnCode = StatusCode.OKAdd.ToString();
                }				
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode = returnCode;
            statusMessage = returnMessage;
            return returnValue;
		}
		#endregion

		#region public int Update(UserInfo userInfo, PmProjectsEntity entity, out string statusCode, out string statusMessage) 更新pm_项目表
		/// <summary>
		/// 更新pm_项目表
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="entity">pm_项目表实体</param>
		/// <param name="statusCode">返回状态码</param>
		/// <param name="statusMessage">返回状态信息</param>
		/// <returns>影响行数</returns>
		public int Update(UserInfo userInfo, PmProjectsEntity entity, out string statusCode, out string statusMessage)
		{
			int returnValue = 0;
            string returnCode = string.Empty;
            string returnMessage = string.Empty;
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, "更新实体");

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                var manager = new PmProjectsManager(dbProvider, userInfo);
                returnValue = manager.UpdateEntity(entity);
				if (returnValue > 0)
                {
                    returnCode = StatusCode.OKUpdate.ToString();
                }
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode = returnCode;
            statusMessage = returnMessage;
            return returnValue;
		}
		#endregion

		#region public DataTable GetDT(UserInfo userInfo) 获取pm_项目表列表
		/// <summary>
		/// 获取pm_项目表列表
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <returns>数据表</returns>
		public DataTable GetDT(UserInfo userInfo)
		{
			var dataTable = new DataTable(PmProjectsTable.TableName);
            var parameter = ParameterUtil.CreateWithOutMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName);

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                dataTable = new PmProjectsManager(dbProvider, userInfo).GetDT(PmProjectsTable.FieldDeleteMark, 0, PmProjectsTable.FieldCreateOn + " DESC ");
                dataTable.TableName = PmProjectsTable.TableName;
            });
            return dataTable;
		}
		#endregion

		#region public DataTable GetDTByPage(UserInfo userInfo, string searchValue, out int recordCount, int pageIndex = 1, int pageSize = 20, string sortExpression = null) 分页获取pm_项目表列表
		/// <summary>
		/// 分页获取pm_项目表列表
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="searchValue">查询关键字</param>
		/// <param name="recordCount">记录数</param>
		/// <param name="pageIndex">当前页</param>
		/// <param name="pageSize">每页显示记录条数</param>
		/// <param name="sortExpression">排序字段</param>
		/// <returns>数据表</returns>
		public DataTable GetDTByPage(UserInfo userInfo, string searchValue, out int recordCount, int pageIndex = 1, int pageSize = 20, string sortExpression = null)
		{
			var dataTable = new DataTable(PmProjectsTable.TableName);
            var returnRecordCount = 0;
            var parameter = ParameterUtil.CreateWithOutMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName);

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                var manager = new PmProjectsManager(dbProvider, userInfo);
                dataTable = manager.GetDTByPage(out returnRecordCount, pageIndex, pageSize, searchValue, sortExpression);
                dataTable.TableName = PmProjectsTable.TableName;
            });
            recordCount = returnRecordCount;
            return dataTable;
		}
		#endregion

		#region public List<PmProjectsEntity> GetListByPage(UserInfo userInfo, string searchValue, out int recordCount, int pageIndex = 1, int pageSize = 20, string sortExpression = null) 分页获取列表
        /// <summary>
        /// 分页获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="searchValue">查询关键字</param>
        /// <param name="recordCount">记录数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示记录条数</param>
        /// <param name="sortExpression">排序字段</param>
        /// <returns>数据表</returns>
        public List<PmProjectsEntity> GetListByPage(UserInfo userInfo, string searchValue, out int recordCount, int pageIndex = 1, int pageSize = 20, string sortExpression = null)
        {
            List<PmProjectsEntity> list = new List<PmProjectsEntity>();
            var returnRecordCount = 0;
            var parameter = ParameterUtil.CreateWithOutMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName);

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                var manager = new PmProjectsManager(dbProvider, userInfo);
                var dataTable = manager.GetDTByPage(out returnRecordCount, pageIndex, pageSize, searchValue, sortExpression);
                list = BaseEntity.GetList<PmProjectsEntity>(dataTable);
            });
            recordCount = returnRecordCount;
            return list;
        }
        #endregion

		#region public PmProjectsEntity GetEntity(UserInfo userInfo, string id) 获取pm_项目表实体
		/// <summary>
		/// 得到pm_项目表实体
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="id">主鍵</param>
		/// <returns>实体</returns>
		public PmProjectsEntity GetEntity(UserInfo userInfo, string id)
		{
            PmProjectsEntity entity = null;
            var parameter = ParameterUtil.CreateWithOutMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName);

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                entity = new PmProjectsManager(dbProvider, userInfo).GetEntity(id);
            });
            return entity;
		}
		#endregion

		#region public DataTable GetDTByIds(UserInfo userInfo, string[] ids) 根据主键数组获取数据
		/// <summary>
		/// 根据主键数组获取数据
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="ids">主鍵</param>
		/// <returns>数据表</returns>
		public DataTable GetDTByIds(UserInfo userInfo, string[] ids)
		{
            var dataTable = new DataTable(PmProjectsTable.TableName);
            var parameter = ParameterUtil.CreateWithOutMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName);

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                dataTable = new PmProjectsManager(dbProvider, userInfo).GetDT(PmProjectsTable.FieldId, ids, PmProjectsTable.FieldCreateOn + " DESC ");
                dataTable.TableName = PmProjectsTable.TableName;
            });

            return dataTable;
		}
		#endregion
		
		#region public DataTable GetDTByValues(UserInfo userInfo, List<KeyValuePair<string, object>> parameters) 根据条件获取数据
		/// <summary>
		/// 根据条件获取数据
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="parameters">参数</param>
		/// <returns>数据表</returns>
		public DataTable GetDTByValues(UserInfo userInfo, List<KeyValuePair<string, object>> parameters)
		{
			var dataTable = new DataTable(PmProjectsTable.TableName);
            var parameter = ParameterUtil.CreateWithOutMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName);

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                dataTable = new PmProjectsManager(dbProvider, userInfo).GetDT(parameters);
                dataTable.TableName = PmProjectsTable.TableName;
            });
            return dataTable;
		}
		#endregion
		
		#region public int BatchSave(UserInfo userInfo, List<PmProjectsEntity> entites) 批量保存数据
		/// <summary>
		/// 批量保存数据
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="entites">pm_项目表实体列表</param>
		/// <returns>影响行数</returns>
		public int BatchSave(UserInfo userInfo, List<PmProjectsEntity> entites)
		{
			var returnValue = 0;
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, "批量保存数据");

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                returnValue += entites.Sum(entity => new PmProjectsManager(dbProvider, userInfo).Update(entity));
            });

            return returnValue;
		}
		#endregion
		
		#region public int Delete(UserInfo userInfo, string id) 删除指定数据
		/// <summary>
		/// 删除指定数据
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="id">主鍵</param>
		/// <returns>影响行数</returns>
		public int Delete(UserInfo userInfo, string id)
		{
			var returnValue = 0;
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, "删除指定数据", "主键：" + id);

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                returnValue = new PmProjectsManager(dbProvider, userInfo).Delete(id);
            });

            return returnValue;
		}
		#endregion

		#region public int BatchDelete(UserInfo userInfo, string[] ids) 批量删除数据
		/// <summary>
		/// 批量删除数据
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="ids">主键数组</param>
		/// <returns>影响行数</returns>
		public int BatchDelete(UserInfo userInfo, string[] ids)
		{
			var returnValue = 0;
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, "批量删除数据");

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                returnValue = new PmProjectsManager(dbProvider, userInfo).Delete(ids);
            });
            return returnValue;
		}
		#endregion

		#region public int SetDeleted(UserInfo userInfo, string[] ids) 批量设置删除标志
		/// <summary>
		/// 批量设置删除标志
		/// </summary>
		/// <param name="userInfo">用户</param>
		/// <param name="ids">主键数组</param>
		/// <returns>影响行数</returns>
		public int SetDeleted(UserInfo userInfo, string[] ids)
		{
			var returnValue = 0;
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, "批量设置删除标志");

            ServiceUtil.ProcessBusinessDb(userInfo, parameter, dbProvider =>
            {
                //returnValue = new PmProjectsManager(dbProvider, userInfo).SetDeleted(ids);
				returnValue = new PmProjectsManager(dbProvider, userInfo).SetProperty(PmProjectsTable.FieldId, ids, PmProjectsTable.FieldDeleteMark, "1");
				
            });

            return returnValue;
		}
		#endregion
	}
}
